package org.ucas.faker.web.service.graph;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.ucas.faker.web.controller.BaseController;
import org.ucas.faker.web.controller.PatentController;
import org.ucas.faker.web.dao.graph.GraphPatentMapper;
import org.ucas.faker.web.fetcher.FetchExecutor;
import org.ucas.faker.web.fetcher.FetchReqBuilder;
import org.ucas.faker.web.fetcher.FetchRequest;
import org.ucas.faker.web.fetcher.FetchResult;
import org.ucas.faker.web.utils.feature.BranchAndEffect;
import org.ucas.faker.web.utils.feature.TechniqueEffectMap;
import org.ucas.faker.web.utils.graph.TechBranchEffect;

import javax.transaction.Transactional;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created by Wang Chong on 17-7-10.
 */
@Transactional
@Service
public class SpecialGraphAndMapService extends BaseController{

  @Autowired
  private GraphPatentMapper graphPatentMapper;
  
  @Autowired private FetchExecutor fetcher;
  
  @Autowired PatentController p;//=new PatentController();
  
//迁移开始***非通用图***
  //featureandeffect
  public Map<String,List<String> > graph_7001(long depotId) throws IllegalAccessException, InstantiationException{
	    TechniqueEffectMap fes = new TechniqueEffectMap();
		//List<TechBranchEffect> tbe = mapper.GetBranchAndEffect();
	   /* List<TechBranchEffect> tbe = graphPatentMapper.GetBranchAndEffect();
   
		List<List<String> > features = new ArrayList<>();
		List<List<String> > effects = new ArrayList<>();
		
		for(TechBranchEffect aaa : tbe){
			List<String> fea = new ArrayList<String>();
			List<String> eff = new ArrayList<String>();
			
			for(String s:aaa.getTech_branch().split("#")){
				fea.add(s);
			}
			for(String s:aaa.getTech_effect().split("#")){
				eff.add(s);
			}
			features.add(fea);
			effects.add(eff);
		}*/
		
		//new start
	    //FeatureGenTask feaGen=new FeatureGenTask();
	    //feaGen.syncGenFeature(currentDepotId());
	    
	    List<List<String> > features = new ArrayList<>();
		List<List<String> > effects = new ArrayList<>();
		//FetchReqBuilder requestBuilder = FetchReqBuilder.instance().depot(currentDepotId());
	    /*FetchReqBuilder requestBuilder = FetchReqBuilder.instance().depot(depotId);
	    requestBuilder.select("branch", "effect").from("feature");
	    
	    FetchRequest req = requestBuilder.build();
        FetchResult result = fetcher.fetch(req);*/
        
        
        List<BranchAndEffect> feaAndEfflist = p.branchAndEffects(depotId);
        //branch
        List<String> basisValueList = new ArrayList<>();//result.column("branch");
        //effect
        List<String> branchValueList = new ArrayList<>();//result.column("effect");
        
        for(BranchAndEffect be:feaAndEfflist) {
        	basisValueList.add(be.getBranch());
        	branchValueList.add(be.getEffect());
        }
        	      
        
        List<String> a = basisValueList;
        List<String> b = branchValueList;
        
        System.out.println("********:"+a.size()+" "+b.size());
        for(int i=0;i<a.size();i++){
			List<String> fea = new ArrayList<String>();
			List<String> eff = new ArrayList<String>();
			
			if(a.get(i).length()!=0) {
				for(String s:a.get(i).split("#")){
					fea.add(s);		
			}
			}else {
				fea.add("");	
			}
			
			if(b.get(i).length()!=0) {
				for(String s:b.get(i).split("#")){
					eff.add(s);
			}
			}else {
				eff.add("");
			}
				
			
			features.add(fea);
			effects.add(eff);
			//System.out.println("#"+aaa.getTech_branch()+"#"+aaa.getTech_effect()+"#");
			//fes.
		}
        
        /*for(int i=0;i<features.size();i++) {
        	for(int j=0;j<features.get(i).size();j++) {
        		System.out.println("画图数据，特征："+features.get(i).get(j));
        	}
        }
        for(int i=0;i<effects.size();i++) {
        	for(int j=0;j<effects.get(i).size();j++) {
        		System.out.println("画图数据，功效："+effects.get(i).get(j));
        	}
        }*/
        //new end
		return fes.CountFeaturesAndEffects(features,effects,feaAndEfflist);
}
  
  /*public Map<String,List<String> > graph_7001backup(long depotId){
	    TechniqueEffectMap fes = new TechniqueEffectMap();
		//List<TechBranchEffect> tbe = mapper.GetBranchAndEffect();
	    List<TechBranchEffect> tbe = graphPatentMapper.GetBranchAndEffect();
   
		List<List<String> > features = new ArrayList<>();
		List<List<String> > effects = new ArrayList<>();
		
		for(TechBranchEffect aaa : tbe){
			List<String> fea = new ArrayList<String>();
			List<String> eff = new ArrayList<String>();
			
			for(String s:aaa.getTech_branch().split("#")){
				fea.add(s);
			}
			for(String s:aaa.getTech_effect().split("#")){
				eff.add(s);
			}
			features.add(fea);
			effects.add(eff);
		}
		
		//new start
	    //FeatureGenTask feaGen=new FeatureGenTask();
	    //feaGen.syncGenFeature(currentDepotId());
	    
	    List<List<String> > features = new ArrayList<>();
		List<List<String> > effects = new ArrayList<>();
		//FetchReqBuilder requestBuilder = FetchReqBuilder.instance().depot(currentDepotId());
	    FetchReqBuilder requestBuilder = FetchReqBuilder.instance().depot(depotId);
	    requestBuilder.select("branch", "effect").from("feature");
	    
	    FetchRequest req = requestBuilder.build();
        FetchResult result = fetcher.fetch(req);
        
	    List basisValueList = result.column("branch");
        List branchValueList = result.column("effect");
        
        List<String> a = basisValueList;
        List<String> b = branchValueList;
        for(int i=0;i<a.size();i++){
			List<String> fea = new ArrayList<String>();
			List<String> eff = new ArrayList<String>();
			
			for(String s:a.get(i).split("#")){
				fea.add(s);
			}
			for(String s:b.get(i).split("#")){
				eff.add(s);
			}
			features.add(fea);
			effects.add(eff);
			//System.out.println("#"+aaa.getTech_branch()+"#"+aaa.getTech_effect()+"#");
			//fes.
		}
        
        //new end
		return fes.CountFeaturesAndEffects(features,effects);
}*/
//中国各省3006
  public List<List<String>> graph_2006(long depotId){
	  List<String> xAxis = new LinkedList<>();
	  List<String> yValue0 = new LinkedList<>();
	  
	  HashMap<String,Long> provinceAmount = new HashMap<>();
	  String[] province= {"北京","天津","上海","重庆","河北","河南","云南","辽宁","黑龙江","湖南",
			  "安徽", "山东","新疆","江苏","浙江","江西","湖北","广西","甘肃","山西","内蒙古","陕西","吉林","福建","贵州","广东","青海","西藏",
			  "四川","宁夏","海南","台湾","香港","澳门","南海诸岛"};
	  
	 
	  for(int i=0;i<province.length;i++) {
		  provinceAmount.put(province[i], (long) 0);
	  }
	  //需要更改，改为省市字段
	  String column1="apr";
	  String column2="apppro_count";
	  FetchReqBuilder requestBuilder = FetchReqBuilder.instance().depot(depotId);
	  requestBuilder.select(column1).count("*",column2).group(column1).not_null(column1).order(false, column2);
	    
	  FetchRequest req = requestBuilder.build();
      FetchResult result = fetcher.fetch(req);

      List<String> provinceName = result.column(column1);
      List<Long> apppro_count = result.column(column2);
     /* System.out.println("provinceName:*******************");
      for(int i=0;i<provinceName.size();i++) {
    	  System.out.println(provinceName.get(i));
      }
      System.out.println("apppro_count:*******************");
      for(int i=0;i<apppro_count.size();i++) {
    	  System.out.println(apppro_count.get(i));
      }
      System.out.println("apppro_count:*******************");*/
      //测试数据
      /*for(int i=0;i<province.length;i++) {
    	  provinceName.add(province[i]+"省");
    	  apppro_count.add((long) i);
      }*/
      
      //测试数据
      //省市规范化
      for(int i=0;i<provinceName.size();i++) {
    	  for(int j=0;j<province.length;j++) {
    		  if(provinceName.get(i).contains(province[j])) {
    			  provinceName.set(i, province[j]);
    		  }
    	  }
      }
      
      
      //如果含有省市数据，存入结果
      for(int i=0;i<provinceName.size();i++) {
    	  String appprovince=(String) provinceName.get(i);
		  long amount=(long) apppro_count.get(i);		  		  
		  if(provinceAmount.containsKey(appprovince)) {
			  provinceAmount.put(appprovince, amount);
		  }	
      }
      
      
	  //List<HashMap> ListGraph = graphPatentMapper.select_2006(flowId);
	  //Iterator<HashMap> it = ListGraph.iterator();
	 /* while(it.hasNext()){
		  HashMap hm = it.next();
		  String appprovince=hm.get("applican_province").toString();
		  long amount=(Long)hm.get("amount");		  		  
		  if(provinceAmount.containsKey(appprovince)) {
			  provinceAmount.put(appprovince, provinceAmount.get(appprovince)+amount);
		  }			  
		
	  }*/
	  
	  Iterator iter = provinceAmount.entrySet().iterator();
	  while (iter.hasNext()) {
		  Map.Entry entry = (Map.Entry) iter.next();
		  yValue0.add(entry.getValue().toString());
		  xAxis.add(entry.getKey().toString());
	  }
	  
	  List< List<String> > finalresult= new LinkedList<>();
	  finalresult.add(xAxis);
	  finalresult.add(yValue0); 
	  
	  for(int i=0;i<xAxis.size();i++) {
    	  System.out.println("i:"+xAxis.get(i)+" "+yValue0.get(i));
      }
	  
	  return finalresult;
  }
  
  public List<List<String>> graph_2006backup(long flowId){
	  List<String> xAxis = new LinkedList<>();
	  List<String> yValue0 = new LinkedList<>();
	  
	  HashMap<String,Long> provinceAmount = new HashMap<>();
	  String[] province= {"北京","天津","上海","重庆","河北","河南","云南","辽宁","黑龙江","湖南",
			  "安徽", "山东","新疆","江苏","浙江","江西","湖北","广西","甘肃","山西","内蒙古","陕西","吉林","福建","贵州","广东","青海","西藏",
			  "四川","宁夏","海南","台湾","香港","澳门"};
	  
	  for(int i=0;i<province.length;i++) {
		  provinceAmount.put(province[i], (long) 0);
		  xAxis.add(province[i]);
	  }
	  	  
	  List<HashMap> ListGraph = graphPatentMapper.select_2006(flowId);
	  Iterator<HashMap> it = ListGraph.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  String appprovince=hm.get("applican_province").toString();
		  long amount=(Long)hm.get("amount");		  		  
		  if(provinceAmount.containsKey(appprovince)) {
			  provinceAmount.put(appprovince, provinceAmount.get(appprovince)+amount);
		  }			  
		  //yValue0.add(((Long)hm.get("amount")).toString());
	  }
	  
	  Iterator iter = provinceAmount.entrySet().iterator();
	  while (iter.hasNext()) {
		  Map.Entry entry = (Map.Entry) iter.next();
		  yValue0.add(entry.getValue().toString());
		  //System.out.println(entry.getValue().toString());
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(xAxis);
	  result.add(yValue0); 
	  
	  return result;
  }
//迁移结束***非通用图***
  
  //#graph-1001
  public List<List<String>> graph_1001_x_Axis(){
	  //文字描述
	  List<String> commentList = new LinkedList<>();
	  String comment="从以上图表可以看出，以下三年申请的专利数量最多，分别为：";
	  int counttmp=1;
	  int countmax=3;
	  //文字描述
 
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  
	  List<HashMap> ListGraph1001 = graphPatentMapper.select_1001();
	  Iterator<HashMap> it = ListGraph1001.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("application_year").toString());
		  valueY.add(((Long)hm.get("application_amount")).toString());
		  //文字描述
		  if(counttmp<=countmax) {
			  comment+= hm.get("application_year").toString()+"年"+((Long)hm.get("application_amount")).toString()+"件";
			  if(counttmp==countmax) {
				  comment+="。";
			  }
			  else {
				  comment+="；";
			  }
			  counttmp++;
		  }
		 //文字描述
	  }
	  
	  //System.out.println(comment);
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  //文字描述
	  commentList.add(comment);
	  result.add(commentList); 
	  //文字描述
	  return result;
  }
  
//#graph-2001
  public List<List<String>> graph_2001(long flowId){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  
	  List<HashMap> ListGraph21001 = graphPatentMapper.select_2001(flowId);
	  Iterator<HashMap> it = ListGraph21001.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("ap").toString());
		  valueY.add(((Long)hm.get("amount")).toString());
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  
	  return result;
  }
  

  
  
  
  
  
//#graph-3001
  public List<List<String>> graph_30011(){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  
	  List<HashMap> ListGraph3001 = graphPatentMapper.select_30011();
	  Iterator<HashMap> it = ListGraph3001.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("ap").toString());
		  valueY.add(((Long)hm.get("amount")).toString());
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  
	  return result;
  }

//#graph-4001
  public List<List<String>> graph_4001_x_Axis(){

	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  
	  List<HashMap> ListGraph4001 = graphPatentMapper.select_4001();
	  Iterator<HashMap> it = ListGraph4001.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("ic").toString());
		  valueY.add(((Long)hm.get("application_amount")).toString());
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY);  
	  return result;
  }

  
//#graph-6001
  public List<List<String>> graph_6001(){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  List<String> valueY2 = new LinkedList<>();
	  List<String> valueY3 = new LinkedList<>();
	  List<String> valueY4 = new LinkedList<>();
	  List<String> valueY5 = new LinkedList<>();
	  List<String> valueY6 = new LinkedList<>();
	  List<String> valueY7 = new LinkedList<>();
	  List<String> valueY8 = new LinkedList<>();
	  List<String> valueY9 = new LinkedList<>();
	  List<String> valueY10 = new LinkedList<>();
	  List<String> valueYname = new LinkedList<>();
	  //
	  Calendar a=Calendar.getInstance();
	  int maxyear=a.get(Calendar.YEAR);
	  int minyear=1980;

	  List<HashMap> ListGraph60011 = graphPatentMapper.select_60011();
	  Iterator<HashMap> it1 = ListGraph60011.iterator();
	  int count=0;
	  Map top10name=new HashMap();
	  while(it1.hasNext()){
		  HashMap hm = it1.next();
		  top10name.put("top"+count, hm.get("ic").toString());
		  valueYname.add(hm.get("ic").toString());
		  count++;
	  }
	  List<HashMap> ListGraph60012 = graphPatentMapper.select_60012(top10name);
	  Iterator<HashMap> it = ListGraph60012.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("application_year").toString());
		  if(hm.get("top0")!=null)
			  valueY.add(hm.get("top0").toString());
		  else
			  valueY.add("0");
		  if(hm.get("top1")!=null)
			  valueY2.add(hm.get("top1").toString());
		  else
			  valueY2.add("0");
		  if(hm.get("top2")!=null)
			  valueY3.add(hm.get("top2").toString());
		  else
			  valueY3.add("0");
		  if(hm.get("top3")!=null)
			  valueY4.add(hm.get("top3").toString());
		  else
			  valueY4.add("0");
		  if(hm.get("top4")!=null)
			  valueY5.add(hm.get("top4").toString());
		  else
			  valueY5.add("0");
		  if(hm.get("top5")!=null)
			  valueY6.add(hm.get("top5").toString());
		  else
			  valueY6.add("0");
		  if(hm.get("top6")!=null)
			  valueY7.add(hm.get("top6").toString());
		  else
			  valueY7.add("0");
		  if(hm.get("top7")!=null)
			  valueY8.add(hm.get("top7").toString());
		  else
			  valueY8.add("0");
		  if(hm.get("top8")!=null)
			  valueY9.add(hm.get("top8").toString());
		  else
			  valueY9.add("0");
		  if(hm.get("top9")!=null)
			  valueY10.add(hm.get("top9").toString());
		  else
			  valueY10.add("0");

		  count++;
	  }

	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  result.add(valueY2); 
	  result.add(valueY3); 
	  result.add(valueY4); 
	  result.add(valueY5); 
	  result.add(valueY6); 
	  result.add(valueY7); 
	  result.add(valueY8); 
	  result.add(valueY9); 
	  result.add(valueY10); 
	  result.add(valueYname); 
	  return result;
  }
  //#graph-5001

  public List<List<String>> graph_5001_x_Axis(long flowId){
	  //文字描述
	  List<String> commentList = new LinkedList<>();
	  String comment="从以上图表可以看出，以下三年申请的专利数量最多，分别为：";
	  int counttmp=0;
	  int countmax=3;
	  long sum=0;
	  String []top3name=new String[countmax];
	  long []top3amount= new long[countmax];
	  Arrays.fill(top3name," ");
	  Arrays.fill(top3amount,0);
	  float top3per=0;
	  //文字描述
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  
	  List<HashMap> ListGraph5001 = graphPatentMapper.select_5001(flowId);
	  Iterator<HashMap> it = ListGraph5001.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("application_year").toString());
		  valueY.add(((Long)hm.get("application_amount")).toString());
		  //文字描述
		  if((Long)hm.get("application_amount")>=top3amount[0]) {
			  top3amount[2]=top3amount[1];
			  top3name[2]=top3name[1];
			  top3amount[1]=top3amount[0];
			  top3name[1]=top3name[0];
			  top3amount[0]=(Long)hm.get("application_amount");
			  top3name[0]=hm.get("application_year").toString();
		  }else if((Long)hm.get("application_amount")>=top3amount[1]) {
			  top3amount[2]=top3amount[1];
			  top3name[2]=top3name[1];
			  top3amount[1]=(Long)hm.get("application_amount");
			  top3name[1]=hm.get("application_year").toString();
		  }else if((Long)hm.get("application_amount")>=top3amount[2]) {
			  top3amount[2]=(Long)hm.get("application_amount");
			  top3name[2]=hm.get("application_year").toString(); 
		  }
		  sum+= (Long)hm.get("application_amount");
		 //文字描述
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY);  
	  //文字描述	
	  counttmp=0;
	  while(counttmp<countmax) {
		  comment+= top3name[counttmp]+"年"+Long.toString(top3amount[counttmp])+"件";
		  if(counttmp==countmax-1) {
			  comment+="，";
		  }
		  else {
			  comment+="、";
		  }
		  counttmp++;
	  }
	  counttmp=0;
	  comment+="占所分析专利的";
	  while(counttmp<countmax) {
		  
		  top3per=(float)top3amount[counttmp]/(float)sum*100;
		  DecimalFormat decimalFormat=new DecimalFormat(".000");//构造方法的字符格式这里如果小数不足2位,会以0补足.
		  comment+= decimalFormat.format(top3per);
		  comment+= "%";
		  if(counttmp==countmax-1) {
			  comment+="。";
		  }
		  else {
			  comment+="、";
		  }
		  counttmp++;
	  }
	  commentList.add(comment);
	  result.add(commentList); 
	  //文字描述
	  return result;
  }
  
  //#graph-5002
  public List<List<String>> graph_5002(long flowId){
	  //文字描述
	  List<String> commentList = new LinkedList<>();
	  String comment="从以上图表可以看出，以下三年授权的专利数量最多，分别为：";
	  int counttmp=0;
	  int countmax=3;
	  long sum=0;
	  String []top3name=new String[countmax];
	  long []top3amount= new long[countmax];
	  Arrays.fill(top3name," ");
	  Arrays.fill(top3amount,0);
	  float top3per=0;
	  //文字描述

	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  
	  List<HashMap> ListGraph5002 = graphPatentMapper.select_5002(flowId);
	  Iterator<HashMap> it = ListGraph5002.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("application_year").toString());
		  valueY.add(((Long)hm.get("granted_amount")).toString());
		  //文字描述
		  if((Long)hm.get("granted_amount")>=top3amount[0]) {
			  top3amount[2]=top3amount[1];
			  top3name[2]=top3name[1];
			  top3amount[1]=top3amount[0];
			  top3name[1]=top3name[0];
			  top3amount[0]=(Long)hm.get("granted_amount");
			  top3name[0]=hm.get("application_year").toString();
		  }else if((Long)hm.get("granted_amount")>=top3amount[1]) {
			  top3amount[2]=top3amount[1];
			  top3name[2]=top3name[1];
			  top3amount[1]=(Long)hm.get("granted_amount");
			  top3name[1]=hm.get("application_year").toString();
		  }else if((Long)hm.get("granted_amount")>=top3amount[2]) {
			  top3amount[2]=(Long)hm.get("granted_amount");
			  top3name[2]=hm.get("application_year").toString(); 
		  }
		  sum+= (Long)hm.get("granted_amount");
		 //文字描述
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY);  
	  //文字描述	
	  counttmp=0;
	  while(counttmp<countmax) {
		  comment+= top3name[counttmp]+"年"+Long.toString(top3amount[counttmp])+"件";
		  if(counttmp==countmax-1) {
			  comment+="，";
		  }
		  else {
			  comment+="、";
		  }
		  counttmp++;
	  }
	  counttmp=0;
	  comment+="占所分析专利的";
	  while(counttmp<countmax) {
		  
		  top3per=(float)top3amount[counttmp]/(float)sum*100;
		  DecimalFormat decimalFormat=new DecimalFormat(".000");//构造方法的字符格式这里如果小数不足2位,会以0补足.
		  comment+= decimalFormat.format(top3per);
		  comment+= "%";
		  if(counttmp==countmax-1) {
			  comment+="。";
		  }
		  else {
			  comment+="、";
		  }
		  counttmp++;
	  }
	  commentList.add(comment);
	  result.add(commentList); 
	  //文字描述
	  return result;
  }

  //#graph-5003
  public List<List<String>> graph_5003(long flowId){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  List<String> valueY2 = new LinkedList<>();
	  
	  List<HashMap> ListGraph5001 = graphPatentMapper.select_5001(flowId);
	  Iterator<HashMap> it = ListGraph5001.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("application_year").toString());
		  valueY.add(((Long)hm.get("application_amount")).toString());
	  }
	  
	  List<HashMap> ListGraph5002 = graphPatentMapper.select_5002(flowId);
	  Iterator<HashMap> it2 = ListGraph5002.iterator();
	  while(it2.hasNext()){
		  HashMap hm2 = it2.next();
		  valueY2.add(((Long)hm2.get("granted_amount")).toString());
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY);  
	  result.add(valueY2);
	  return result;
  }
  public List<String> graph_5003_y_apply(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=37;i++)
		  valueY.add(String.valueOf(i));
	  return valueY;
  }
  public List<String> graph_5003_y_grant(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=37;i++)
		  valueY.add(String.valueOf(i+10));
	  return valueY;
  }

  //#graph-5004
  public List<List<String>> graph_5004(){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  List<String> valueY2 = new LinkedList<>();
	  List<String> valueY3 = new LinkedList<>();
	  
	  List<HashMap> ListGraph5004 = graphPatentMapper.select_5004();
	  Iterator<HashMap> it = ListGraph5004.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("application_year").toString());
		  valueY.add(((BigDecimal)hm.get("invention")).toString());
		  valueY2.add(((BigDecimal)hm.get("utilitymodels")).toString());
		  valueY3.add(((BigDecimal)hm.get("design")).toString());
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  result.add(valueY2); 
	  result.add(valueY3); 
	  return result;
  }

  //#graph-5005
  public List<List<String>> graph_5005(){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  List<String> valueY2 = new LinkedList<>();
	  List<String> valueY3 = new LinkedList<>();
	  
	  List<HashMap> ListGraph5005 = graphPatentMapper.select_5005();
	  Iterator<HashMap> it = ListGraph5005.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("application_year").toString());
		  valueY.add(((BigDecimal)hm.get("valid")).toString());
		  valueY2.add(((BigDecimal)hm.get("invalid")).toString());
		  valueY3.add(((BigDecimal)hm.get("review")).toString());
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  result.add(valueY2); 
	  result.add(valueY3); 
	  return result;
  }


  //#graph-5006
  //企业名称
  public List<List<String>> graph_5006(){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  
	  List<HashMap> ListGraph5006 = graphPatentMapper.select_5006();
	  Iterator<HashMap> it = ListGraph5006.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("ap").toString());
		  valueY.add(((Long)hm.get("amount")).toString());
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  
	  return result;
  }
  //专利申请量
  public List<String> graph_5006_y_zlsql(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=19;i++)
		  valueY.add(String.valueOf(i+10));
	  return valueY;
  }

  //#graph-5007
  public List<List<String>> graph_5007(){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  List<String> valueY2 = new LinkedList<>();
	  List<String> valueY3 = new LinkedList<>();
	  List<String> valueY4 = new LinkedList<>();
	  List<String> valueY5 = new LinkedList<>();
	  List<String> valueY6 = new LinkedList<>();
	  List<String> valueY7 = new LinkedList<>();
	  List<String> valueY8 = new LinkedList<>();
	  List<String> valueY9 = new LinkedList<>();
	  List<String> valueY10 = new LinkedList<>();
	  List<String> valueYname = new LinkedList<>();
	  //
	  Calendar a=Calendar.getInstance();
	  int maxyear=a.get(Calendar.YEAR);
	  int minyear=1980;
	  /*for(int i=minyear;i<=maxyear;i++){
		  axisX.add(String.valueOf(i));
		  
	  }*/
	  
	  //获取前10企业
	  List<HashMap> ListGraph50071 = graphPatentMapper.select_50071();
	  //List<String> top10name = new LinkedList<>();
	  Iterator<HashMap> it1 = ListGraph50071.iterator();
	  int count=0;
	  Map top10name=new HashMap();
	  while(it1.hasNext()){
		  HashMap hm = it1.next();
		  top10name.put("top"+count, hm.get("ap").toString());
		  valueYname.add(hm.get("ap").toString());
		  count++;
	  }
	  
	  List<HashMap> ListGraph50072 = graphPatentMapper.select_50072(top10name);
	  Iterator<HashMap> it = ListGraph50072.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  //System.out.println(hm.get("ap").toString());
		  axisX.add(hm.get("application_year").toString());
		  valueY.add(hm.get("top0").toString());
		  valueY2.add(hm.get("top1").toString());
		  valueY3.add(hm.get("top2").toString());
		  valueY4.add(hm.get("top3").toString());
		  valueY5.add(hm.get("top4").toString());
		  valueY6.add(hm.get("top5").toString());
		  valueY7.add(hm.get("top6").toString());
		  valueY8.add(hm.get("top7").toString());
		  valueY9.add(hm.get("top8").toString());
		  valueY10.add(hm.get("top9").toString());
		  count++;
	  }
	  
	  
	  //****************
	  /*List ids = new ArrayList();
	  for(int i=minyear;i<=maxyear;i++){
		  axisX.add(String.valueOf(i));
		  ids.add("sum(case application_year when \""+ String.valueOf(i)+"\" then 1 else 0 end) as \"y"+String.valueOf(i)+"\"");
		  System.out.println("sum(case application_year when \""+ String.valueOf(i)+"\" then 1 else 0 end) as \"y"+String.valueOf(i)+"\"");
	  }
	  List<HashMap> ListGraph5007 = graphPatentMapper.select_5007(ids);
	  //List<String> top10name = new LinkedList<>();
	  Iterator<HashMap> it = ListGraph5007.iterator();
	  int count=1;
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  //System.out.println(hm.get("ap").toString());
		  if(count==1){
			  for(int i=minyear;i<=maxyear;i++){
				  valueY.add(((BigDecimal)hm.get("y"+String.valueOf(i))).toString());
			  }
		  }else if(count==2){
			  for(int i=minyear;i<=maxyear;i++){
				  valueY2.add(((BigDecimal)hm.get("y"+String.valueOf(i))).toString());
			  }
		  }else if(count==3){
			  for(int i=minyear;i<=maxyear;i++){
				  valueY3.add(((BigDecimal)hm.get("y"+String.valueOf(i))).toString());
			  }
		  }else if(count==4){
			  for(int i=minyear;i<=maxyear;i++){
				  valueY4.add(((BigDecimal)hm.get("y"+String.valueOf(i))).toString());
			  }
		  }else if(count==5){
			  for(int i=minyear;i<=maxyear;i++){
				  valueY5.add(((BigDecimal)hm.get("y"+String.valueOf(i))).toString());
			  }
		  }else if(count==6){
			  for(int i=minyear;i<=maxyear;i++){
				  valueY6.add(((BigDecimal)hm.get("y"+String.valueOf(i))).toString());
			  }
		  }else if(count==7){
			  for(int i=minyear;i<=maxyear;i++){
				  valueY7.add(((BigDecimal)hm.get("y"+String.valueOf(i))).toString());
			  }
		  }else if(count==8){
			  for(int i=minyear;i<=maxyear;i++){
				  valueY8.add(((BigDecimal)hm.get("y"+String.valueOf(i))).toString());
			  }
		  }else if(count==9){
			  for(int i=minyear;i<=maxyear;i++){
				  valueY9.add(((BigDecimal)hm.get("y"+String.valueOf(i))).toString());
			  }
		  }else if(count==10){
			  for(int i=minyear;i<=maxyear;i++){
				  valueY10.add(((BigDecimal)hm.get("y"+String.valueOf(i))).toString());
			  }
		  }
		  
		  
		  valueYname.add(hm.get("ap").toString());
		  count++;
	  }
	  
	  */
	  //******************
	  
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  result.add(valueY2); 
	  result.add(valueY3); 
	  result.add(valueY4); 
	  result.add(valueY5); 
	  result.add(valueY6); 
	  result.add(valueY7); 
	  result.add(valueY8); 
	  result.add(valueY9); 
	  result.add(valueY10); 
	  result.add(valueYname); 
	  return result;
  }
  //前十企业年度申请
  //前十企业的企业名称,1-10
  public List<String> graph_5007_y_companyname(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<10;i++)
		  valueY.add("企业"+String.valueOf(i));
	  return valueY;
  }
  //第一个企业每年的数量
  public List<String> graph_5007_y_company1(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=37;i++)
		  valueY.add(String.valueOf(i));
	  return valueY;
  }
  
  public List<String> graph_5007_y_company2(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=37;i++)
		  valueY.add(String.valueOf(i+1));
	  return valueY;
  }

  public List<String> graph_5007_y_company3(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=37;i++)
		  valueY.add(String.valueOf(i+3));
	  return valueY;
  }

  public List<String> graph_5007_y_company4(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=37;i++)
		  valueY.add(String.valueOf(i+4));
	  return valueY;
  }

  public List<String> graph_5007_y_company5(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=37;i++)
		  valueY.add(String.valueOf(i+5));
	  return valueY;
  }

  public List<String> graph_5007_y_company6(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=37;i++)
		  valueY.add(String.valueOf(i+6));
	  return valueY;
  }

  public List<String> graph_5007_y_company7(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=37;i++)
		  valueY.add(String.valueOf(i+7));
	  return valueY;
  }

  public List<String> graph_5007_y_company8(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=37;i++)
		  valueY.add(String.valueOf(i+8));
	  return valueY;
  }

  public List<String> graph_5007_y_company9(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=37;i++)
		  valueY.add(String.valueOf(i+9));
	  return valueY;
  }

  public List<String> graph_5007_y_company10(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=0;i<=37;i++)
		  valueY.add(String.valueOf(i+10));
	  return valueY;
  }

//#graph-5008
  public List<List<String>> graph_5008(){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  List<String> valueY2 = new LinkedList<>();
	  List<String> valueY3 = new LinkedList<>();
	  
	  List<HashMap> ListGraph5008 = graphPatentMapper.select_5008();
	  Iterator<HashMap> it = ListGraph5008.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("ap").toString());
		  valueY.add(((BigDecimal)hm.get("invention")).toString());
		  valueY2.add(((BigDecimal)hm.get("utilitymodels")).toString());
		  valueY3.add(((BigDecimal)hm.get("design")).toString());
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  result.add(valueY2); 
	  result.add(valueY3); 
	  return result;
  }


  //#graph-5009
  public List<List<String>> graph_5009(){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  List<String> valueY2 = new LinkedList<>();
	  List<String> valueY3 = new LinkedList<>();
	  List<String> valueY4 = new LinkedList<>();
	  List<String> valueY5 = new LinkedList<>();
	  //目前数据库字段没有PTV，待补充，此为示查询方法，数据库补充字段后,换为select_5009()
	  List<HashMap> ListGraph5009 = graphPatentMapper.select_5009_noptv();
	  Iterator<HashMap> it = ListGraph5009.iterator();
	  float sum,temp,america,japan,europe,korea,china; 
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  america=Float.valueOf((hm.get("America")).toString());
		  japan=Float.valueOf((hm.get("Japan")).toString());
		  europe=Float.valueOf((hm.get("Europe")).toString());
		  korea=Float.valueOf((hm.get("Korea")).toString());
		  china=Float.valueOf((hm.get("China")).toString());
		  sum=america+japan+europe+korea+china;
		  axisX.add(hm.get("application_year").toString());
		  temp=america/sum*100;
		  valueY.add(String.valueOf(temp));
		  temp=japan/sum*100;
		  valueY2.add(String.valueOf(temp));
		  temp=europe/sum*100;
		  valueY3.add(String.valueOf(temp));
		  temp=korea/sum*100;
		  valueY4.add(String.valueOf(temp));
		  temp=china/sum*100;
		  valueY5.add(String.valueOf(temp));
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  result.add(valueY2); 
	  result.add(valueY3); 
	  result.add(valueY4); 
	  result.add(valueY5); 
	  return result;
  }
  public List<String> graph_5009_y_value(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=2017;i>=1980;i--)
		  valueY.add(String.valueOf(i));
	  return valueY;
  }

  //#graph-5010
  public List<List<String>> graph_5010(){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  List<String> valueY2 = new LinkedList<>();
	  List<String> valueY3 = new LinkedList<>();
	  List<String> valueY4 = new LinkedList<>();
	  List<String> valueY5 = new LinkedList<>();
	  
	  List<HashMap> ListGraph5010 = graphPatentMapper.select_5010();
	  Iterator<HashMap> it = ListGraph5010.iterator();
	  float sum,temp,america,japan,europe,korea,china; 
	  for(int i=1; i<7;i++){
		  axisX.add("0."+i);
	  }
	  axisX.add("0.7-1.0");
	  int array[][]= new int[7][5];
	  int array_i=0;
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  float PTV=Float.valueOf((hm.get("PTV")).toString());
		  if(PTV<=0.1){
			  array_i=0;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }else if(PTV<=0.2){
			  array_i=1;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }else if(PTV<=0.3){
			  array_i=2;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }else if(PTV<=0.4){
			  array_i=3;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }else if(PTV<=0.5){
			  array_i=4;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }else if(PTV<=0.6){
			  array_i=5;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }else if(PTV<=1){
			  array_i=6;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }
	  }
	  for(int i=0;i<7;i++){
		  sum=array[i][0]+array[i][1]+array[i][2]+array[i][3]+array[i][4];
		  valueY.add(String.valueOf(array[i][0]/sum*100));
		  valueY2.add(String.valueOf(array[i][1]/sum*100));
		  valueY3.add(String.valueOf(array[i][2]/sum*100));
		  valueY4.add(String.valueOf(array[i][3]/sum*100));
		  valueY5.add(String.valueOf(array[i][4]/sum*100));
	  }	 
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  result.add(valueY2); 
	  result.add(valueY3); 
	  result.add(valueY4); 
	  result.add(valueY5); 
	  return result;
  }
  
//#graph-5010-noptv
//目前数据库字段没有PTV，待补充，此为示查询方法，数据库补充字段后,换为select_5010()
  public List<List<String>> graph_5010_noptv(){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  List<String> valueY2 = new LinkedList<>();
	  List<String> valueY3 = new LinkedList<>();
	  List<String> valueY4 = new LinkedList<>();
	  List<String> valueY5 = new LinkedList<>();
	  //目前数据库字段没有PTV，待补充，此为示查询方法，数据库补充字段后,换为select_5010()
	  List<HashMap> ListGraph5010 = graphPatentMapper.select_5010_noptv();
	  Iterator<HashMap> it = ListGraph5010.iterator();
	  float sum,temp,america,japan,europe,korea,china; 
	  for(int i=1; i<7;i++){
		  axisX.add("0."+i);
	  }
	  axisX.add("0.7-1.0");
	  int array[][]= new int[7][5];
	  int array_i=0;
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  int PTV=Integer.valueOf((hm.get("inventor_count")).toString());
		  if(PTV<=1){
			  array_i=0;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }else if(PTV<=2){
			  array_i=1;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }else if(PTV<=3){
			  array_i=2;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }else if(PTV<=4){
			  array_i=3;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }else if(PTV<=5){
			  array_i=4;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }else if(PTV<=6){
			  array_i=5;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }else if(PTV<=10){
			  array_i=6;
			  array[array_i][0]+=Integer.valueOf((hm.get("America")).toString());
			  array[array_i][1]+=Integer.valueOf((hm.get("Japan")).toString());
			  array[array_i][2]+=Integer.valueOf((hm.get("Europe")).toString());
			  array[array_i][3]+=Integer.valueOf((hm.get("Korea")).toString());
			  array[array_i][4]+=Integer.valueOf((hm.get("China")).toString());		  
		  }
	  }
	  //float sum,temp,america,japan,europe,korea,china;
	  for(int i=0;i<7;i++){
		  sum=array[i][0]+array[i][1]+array[i][2]+array[i][3]+array[i][4];
		  valueY.add(String.valueOf(array[i][0]/sum*100));
		  valueY2.add(String.valueOf(array[i][1]/sum*100));
		  valueY3.add(String.valueOf(array[i][2]/sum*100));
		  valueY4.add(String.valueOf(array[i][3]/sum*100));
		  valueY5.add(String.valueOf(array[i][4]/sum*100));
	  }	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  result.add(valueY2); 
	  result.add(valueY3); 
	  result.add(valueY4); 
	  result.add(valueY5); 
	  return result;
  }

  //#graph-5011
  public List<List<String>> graph_5011_noptv(){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  List<String> valueY2 = new LinkedList<>();
	  List<String> valueY3 = new LinkedList<>();
	  List<String> valueY4 = new LinkedList<>();
	  List<String> valueY5 = new LinkedList<>();
	  List<String> valueY6 = new LinkedList<>();
	  List<String> valueY7 = new LinkedList<>();
	  List<String> valueY8 = new LinkedList<>();
	  //目前数据库字段没有PTV，待补充，此为示查询方法，数据库补充字段后,换为select_5011()
	  List<HashMap> ListGraph5011 = graphPatentMapper.select_5011_noptv();
	  Iterator<HashMap> it = ListGraph5011.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("applican_province").toString());
		  valueY.add(((BigDecimal)hm.get("tech1")).toString());
		  valueY2.add(((BigDecimal)hm.get("tech2")).toString());
		  valueY3.add(((BigDecimal)hm.get("tech3")).toString());
		  valueY4.add(((BigDecimal)hm.get("tech4")).toString());
		  valueY5.add(((BigDecimal)hm.get("tech5")).toString());
		  valueY6.add(((BigDecimal)hm.get("tech6")).toString());
		  valueY7.add(((BigDecimal)hm.get("tech7")).toString());
		  valueY8.add(((BigDecimal)hm.get("tech8")).toString());
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  result.add(valueY2); 
	  result.add(valueY3); 
	  result.add(valueY4); 
	  result.add(valueY5); 
	  result.add(valueY6); 
	  result.add(valueY7); 
	  result.add(valueY8); 
	  return result;
  }
  public List<String> graph_5011_y_value(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=2017;i>=1980;i--)
		  valueY.add(String.valueOf(i));
	  return valueY;
  }

  //#graph-5012
  public List<List<String>> graph_5012_noptv(){
	  List<String> axisX = new LinkedList<>();
	  List<String> valueY = new LinkedList<>();
	  List<String> valueY2 = new LinkedList<>();
	  List<String> valueY3 = new LinkedList<>();
	  List<String> valueY4 = new LinkedList<>();
	  List<String> valueY5 = new LinkedList<>();
	  List<String> valueY6 = new LinkedList<>();
	  List<String> valueY7 = new LinkedList<>();
	  List<String> valueY8 = new LinkedList<>();
	  //目前数据库字段没有PTV，待补充，此为示查询方法，数据库补充字段后,换为select_5012()
	  List<HashMap> ListGraph5012 = graphPatentMapper.select_5012_noptv();
	  Iterator<HashMap> it = ListGraph5012.iterator();
	  while(it.hasNext()){
		  HashMap hm = it.next();
		  axisX.add(hm.get("ap").toString());
		  valueY.add(((BigDecimal)hm.get("tech1")).toString());
		  valueY2.add(((BigDecimal)hm.get("tech2")).toString());
		  valueY3.add(((BigDecimal)hm.get("tech3")).toString());
		  valueY4.add(((BigDecimal)hm.get("tech4")).toString());
		  valueY5.add(((BigDecimal)hm.get("tech5")).toString());
		  valueY6.add(((BigDecimal)hm.get("tech6")).toString());
		  valueY7.add(((BigDecimal)hm.get("tech7")).toString());
		  valueY8.add(((BigDecimal)hm.get("tech8")).toString());
	  }
	  
	  List< List<String> > result= new LinkedList<>();
	  result.add(axisX);
	  result.add(valueY); 
	  result.add(valueY2); 
	  result.add(valueY3); 
	  result.add(valueY4); 
	  result.add(valueY5); 
	  result.add(valueY6); 
	  result.add(valueY7); 
	  result.add(valueY8); 
	  return result;
  }
  public List<String> graph_5012_y_value(){
	  List<String> valueY = new LinkedList<>();
	  for(int i=2017;i>=1980;i--)
		  valueY.add(String.valueOf(i));
	  return valueY;
  }
  
  public static int partition(long []array,int lo,int hi){
      //固定的切分方式
      long key=array[lo];
      while(lo<hi){
          while(array[hi]>=key&&hi>lo){//从后半部分向前扫描
              hi--;
          }
          array[lo]=array[hi];
          while(array[lo]<=key&&hi>lo){//从前半部分向后扫描
              lo++;
          }
          array[hi]=array[lo];
      }
      array[hi]=key;
      return hi;
  }
  
  public static void sort(long[] array,int lo ,int hi){
      if(lo>=hi){
          return ;
      }
      int index=partition(array,lo,hi);
      sort(array,lo,index-1);
      sort(array,index+1,hi); 
  }
  
  
}
